var app = angular.module("editApp", []),
	groupName = UI.getParameterByName('orgName'),
	groupId = UI.getParameterByName('groupId'),
	ifmlId = UI.getParameterByName('ifmlId'),
	ifmlName = UI.getParameterByName('ifmlName'),
	ifmsId = UI.getParameterByName('ifmsId');
	//取得方案的id值，便于分页后依然选中该方案
	window.ifmIds = ifmlId;
	window.ifmId = ifmsId;
	window.ifmNames = ifmlName;

var timeout_json = function(data, $window) {
	if(data.returnCode == 999994) {
		var ss = 3;
		layer.msg(data.returnMessage + "！<strong class='Ajax_Out'>" + ss + "</strong> 秒后前往登录页", 50, -1);
		var picInt = setInterval(function() {
			if(ss >= 1) {
				ss = ss - 1;
				$('.Ajax_Out').text(ss);
			} else {
				clearInterval(picInt);
				try {
					$window.parent.location.href = data.returnData;
					$window.location.href = data.returnData;
				} catch(e) {
					log('timeout!')
				}
			}
		}, 1000);
		return false;
	}
}

app.config(function($httpProvider) {
	$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
	$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
	// Override $http service's default transformRequest
	$httpProvider.defaults.transformRequest = [function(data) {
		/**
		 * The workhorse; converts an object to x-www-form-urlencoded serialization.
		 * @param {Object} obj
		 * @return {String}
		 */
		var param = function(obj) {
			var query = '';
			var name, value, fullSubName, subName, subValue, innerObj, i;

			for(name in obj) {
				value = obj[name];

				if(value instanceof Array) {
					for(i = 0; i < value.length; ++i) {
						subValue = value[i];
						fullSubName = name + '[' + i + ']';
						innerObj = {};
						innerObj[fullSubName] = subValue;
						query += param(innerObj) + '&';
					}
				} else if(value instanceof Object) {
					for(subName in value) {
						subValue = value[subName];
						fullSubName = name + '[' + subName + ']';
						innerObj = {};
						innerObj[fullSubName] = subValue;
						query += param(innerObj) + '&';
					}
				} else if(value !== undefined && value !== null) {
					query += encodeURIComponent(name) + '=' +
						encodeURIComponent(value) + '&';
				}
			}
			return query.length ? query.substr(0, query.length - 1) : query;
		};
		return angular.isObject(data) && String(data) !== '[object File]' ?
			param(data) :
			data;
	}];
});

app.controller('editCtrl', function($scope, $http, $window, $timeout) {
	var vm = $scope.vm = {
		"groupName":groupName,
		"groupId":groupId,
		"ifmlId":window.ifmIds,
		"ifmsId":window.ifmId,
		"ifmlName":window.ifmNames
	};
	var avoidDup = true;
	$scope.domAjax = function(e) {
		if (window.ifmIds!=null && window.ifmIds.substr(0,1)==','){
			window.ifmIds=window.ifmIds.substr(1);
			window.ifmNames=window.ifmNames.substr(1);
		}
		//给页面‘信息方案选择’元素属性ifm_id赋值
		$scope.vm.ifmlId = window.ifmIds;
		$scope.vm.ifmsId = window.ifmId;
		$scope.vm.ifmlNames = window.ifmlNames;

		if(window.ifmId=="" || window.ifmId==null || window.ifmId==undefined){
			window.ifmId = null;
		}
		
//		if(window.ifmIds!="" && window.ifmIds!=null && window.ifmIds!=undefined){
//			gSchemeNum = 0;
//		}else{
//			gSchemeNum = null;
//			window.ifmIds = null;
//		}
		if(window.ifmIds=="" || window.ifmIds==null || window.ifmIds==undefined){
			window.ifmIds = null;
		}
		
		if (e === 'save') {
			if(avoidDup==false){
				return false;
			}
			
			//取得本次取消勾选的信息方案的id
			var diffSelectArr = [];
			var diffSelectStr = "";
			if($("#moreSelect").attr("ifm_id")){
				var moreSelectArr = $("#moreSelect").attr("ifm_id").split(",");
				if(window.ifmIds){
					var newMoreSelectArr = window.ifmIds.split(",");
					var diffFlag = false;
					for(var i=0; i<moreSelectArr.length; i++){
						for(var j=0; j<newMoreSelectArr.length; j++){
							if(moreSelectArr[i]==newMoreSelectArr[j]){
								diffFlag = true;
								break;
							}else{
								diffFlag = false;
							}
						}
						if(!diffFlag){
							diffSelectArr.push(moreSelectArr[i]);
						}
					}
					diffSelectStr = diffSelectArr.join(",");
				}else{
					diffSelectStr = $("#moreSelect").attr("ifm_id");
				}
			}else{
				diffSelectStr = null;
			}
			//普通信息方案取消勾选后，相对应普通信息方案的敏感信息方案也将被清空
			if(window.ifmIds){
				var ifmIdsPublicArr = window.ifmIds.split(",");
				var flagPub = false;
				for(var i=0; i<ifmIdsPublicArr.length; i++){
					if(ifmIdsPublicArr[i]==window.ifmId){
						flagPub = true;
						break;
					}
				}
				if(!flagPub){
					window.ifmId = null;
				}
			}else{
				window.ifmId = null;
			}
			
			if(window.ifmId != $("#sensitiveSelect").attr("ifm_id")){
				var rptifmId = $("#sensitiveSelect").attr("ifm_id");
			}else{
				var rptifmId = null;
			}
			
			//vmm.gScheme为方案id
			var vmm = $scope.vmm = {
				"groupName":vm.groupName,
				"groupId":groupId,
				"gScheme":window.ifmIds,
				"ifmId":window.ifmId,
				"ropeProgramme":diffSelectStr,
				"rptifmId":rptifmId
			};
			var updateUrl=basePath+'group/changeGroupScheme.do';
			avoidDup =false;
			$.post(updateUrl, vmm).success(function(data) {
				if(data.returnCode==10000){
					layer.msg(data.returnMessage,1,10);
					//保存iframe窗口后，不跳转页面--jquery
					var t = setTimeout(function(){
						window.parent.$(".ktab").find('.pNumBtn a.cur').trigger('click');
						window.parent.layer.closeAll();
					},1000);
					return false;
				}else {
					layer.msg(data.returnMessage, 2, -1);
					avoidDup =true;
					return false;
				} 
			});
		}
	};
});

$(function() {
	laydate.skin('molv');
	$('.ui_select').each(function() {
		var _ = $(this),
			_a = _.find('.ui_s_t'),
			_c = _.find('.ui_s_bk'),
			_ca = _c.find('a');
		_a.live('click', function() {
			_c.slideToggle(200, "easeInSine");
		});
		_ca.live('click', function() {
			$(this).addClass('cur').siblings().removeClass('cur');
			_a.text($(this).text());
			_c.slideToggle(200, "easeInSine");
		});
		_c.live('mouseleave', function() {
			_c.stop(false, true).slideUp(200, "easeInSine");
		});
	});
	$('.ui_select').live('keyup', function(e) {
		var _ = $(this),
			b = _.find('.ui_s_bk'),
			di = 27;
		_.focus();
		e = e || window.event;
		var indx = b.find('a.cur').index() || 0;
		if(e.keyCode == 40) {
			var aindx = indx + 1,
				sct;
			if(rindx >= b.find('a').length) {
				rindx = b.find('a').length;
			}
			b.find('a').eq(aindx).addClass('cur').siblings('a').removeClass('cur');
			sct = aindx * di > 180 ? aindx * di - 80 : 0;
			b.scrollTop(sct);
		} else if(e.keyCode == 38) {
			var rindx = indx - 1,
				sct;
			sct = aindx * di > 100 ? aindx * di : 0;
			if(rindx <= 0) {
				rindx = 0;
			}
			b.find('a').eq(rindx).addClass('cur').siblings('a').removeClass('cur');
			sct = rindx * di > 180 ? rindx * di - 80 : 0;
			b.scrollTop(sct);
		} else if(e.keyCode == 13) {
			b.find('a.cur').trigger('click');
			_.blur();
			_.find('.ui_s_t').blur();
		}
		return false;
	});
	var isSensitiveFlag = "";
	//open edit Layer
	var editExaDataLayer = null;
	$('.editExaDataBtn').live('click', function() {
		$("#oldSelected").val($(this).attr("ifm_id"));
		$("#oldSelectedName").val($(this).attr("ifm_name"));
		isSensitiveFlag = 0;
		var editExaDataLayer = $.layer({
			type: 1,
			title: false,
			offset:['0px',''],//控制坐标的位置
			area: ['900', 'auto'],
			border: [0], //去掉默认边框
			shade: [0.3, '#000'], //去掉遮罩
			closeBtn: [0, false], //去掉默认关闭按钮
			fadeIn: 500,
			move: "#editExaData_tile",
			page: {
				dom: '#editExaDataLayer'
			},
			end: function(){
				curPage = 1;
				$("#ifmName").val("");
				$("#ifmNote").val("");
			}
		});
		//自设关闭
		$('#editExaDataLayer > .closeBtn[data-i=1]').live('click', function() {
			window.ifmIds = $("#oldSelected").val();
			window.ifmNames = $("#oldSelectedName").val();
			layer.close(editExaDataLayer);
		});
	});
	
	$('#editExaDataLayer .ensure').live('click',function(){
		//取得当前弹出层取消勾选的信息方案的id
		var diffSelectNameArr=[],diffSelectIdArr=[],
			diffSelectNameStr = "",diffSelectIdStr = "",
			oldSelectedName = $("#oldSelectedName").val(),
			oldSelectedId = $("#oldSelected").val();
		if(oldSelectedName){
			var oldSelectNameArr = oldSelectedName.split(",");
			var oldSelectIdArr = oldSelectedId.split(",");
			if(window.ifmIds){
				var newMoreSelectNameArr = window.ifmNames.split(",");
				var newMoreSelectIdArr = window.ifmIds.split(",");
				var diffFlag = false;
				for(var i=0; i<oldSelectIdArr.length; i++){
					for(var j=0; j<newMoreSelectIdArr.length; j++){
						if(oldSelectIdArr[i]==newMoreSelectIdArr[j]){
							diffFlag = true;
							break;
						}else{
							diffFlag = false;
						}
					}
					if(!diffFlag){
						diffSelectNameArr.push(oldSelectNameArr[i]);
						diffSelectIdArr.push(oldSelectIdArr[i]);
					}
				}
				diffSelectNameStr = diffSelectNameArr.join(",");
				diffSelectIdStr = diffSelectIdArr.join(",");
			}else{
				diffSelectNameStr = oldSelectedName;
				diffSelectIdStr = oldSelectedId;
			}
		}else{
			diffSelectNameStr = null;
			diffSelectIdStr = null;
		}
		if(diffSelectNameStr){
			params = {
				"groupId": groupId,
				"ifmName": diffSelectNameStr,
				"ifmId": diffSelectIdStr
			}
			$.ajax({
				type: "POST",
				url: basePath + "group/selectModelgroupId.do",
				data: params,
				success: function(data) {
	        		if(data.returnData >0){
	        			$.layer({
		                    title: "温馨提示：",
		                    shade: [0],
		                    area: ['auto','auto'],
		                    dialog: {
		                        msg: data.returnMessage,
		                        btns: 2,
		                        type: -1,
		                        btn: ['确定','取消'],
		                        yes: function() {
		                        	window.parent.location.href = basePath + "report/reportTemplateList.jsp?parId=301";
		                        },
		                        no: function() {
		                        	window.ifmIds = window.ifmIds + ',' + diffSelectIdStr;
		                        	window.ifmNames = window.ifmNames + ',' + diffSelectNameStr;
		                        	$(".pNumBtn a[class=cur]").trigger("click");
		                        }
		                    }
		                });
	        		}else{
	        			layer.closeAll();
	        		}
				},
				error: function(message) {
					layer.msg("操作失败，请重试！", 2, -1);
				}
			});
		}else{
			layer.closeAll();
		}
	});	
	
	var editSensitiveLayer = null;
	$('.editSensitiveBtn').live('click', function() {
		isSensitiveFlag = 1;
		var editSensitiveLayer = $.layer({
			type: 1,
			title: false,
			offset:['0px',''],
			area: ['900', 'auto'],
			border: [0], //去掉默认边框
			shade: [0.3, '#000'], //去掉遮罩
			closeBtn: [0, false], //去掉默认关闭按钮
			fadeIn: 500,
			move: "#editSensitive_tile",
			page: {
				dom: '#editSensitiveLayer'
			}
		});
		//自设关闭
		$('#editSensitiveLayer > .closeBtn[data-i=2],#editSensitiveLayer .ensure').live('click', function() {
			curPage = 1;
			layer.close(editSensitiveLayer);
			$("#sensitiveIfmName").val("");
			$("#sensitiveIfmNote").val("");
		});
	});

	var getSs=function(v){
		if(window.ifmIds&&window.ifmIds!=""){
			var cls=window.ifmIds.split(',');
			for(ii=0;ii<cls.length;ii++){
				if(v==cls[ii]){
					return false || ii;
				}
			}
		}
	}
	var getSs2=function(v){
		if(window.ifmId&&window.ifmId!=""){
			var cls=window.ifmId.split(',');
			for(ii=0;ii<cls.length;ii++){
				if(v==cls[ii]){
					return false || ii;
				}
			}
		}
	}

	var edit = {
//		"queryCheck": function(ids, names) {
//			var $selectShowSpan = $(".editExaDataBtn");
//			var $showSpan = $selectShowSpan.parent().prev("span");
//			$selectShowSpan.attr({
//				ifm_id: ids
//			});
//			$showSpan.attr({
//				ifm_id: ids
//			});
//			$showSpan.text(names);
//		},
		"qTagList": function(_this, ifmIdArr, jsons, pIndex, pageSize) {
			//单页显示总条数为‘全部’时，默认为10000000
			if(isNaN(pageSize)){
				pageSize=10000000;
			}
			var _obj = $(".ktab");
			$.ajax({
				type: "POST",
				url: basePath + "iformation/queryByParamsNN.do?pageIndex=" + pIndex + "&pageSize=" + pageSize,
				data: jsons,
				success: function(data) {
					if(data.returnCode == 10000) {
						var s2 = data.returnData.length;
						if(isSensitiveFlag==0){
							var strHead = "<div class='selects w60'>复选框</div><div class='ifmNames w150'>方案名称</div><div class='ifmNotes w536'>方案备注</div>";
							var strPage = "<div class='pages' style='position:relative;'><div class='ui_page' id='pageArea'></div></div>";
						}else if(isSensitiveFlag==1){
							var strHead = "<div class='selects w60'>单选框</div><div class='ifmNames w150'>方案名称</div><div class='ifmNotes w536'>方案备注</div>";
						}
						if(s2 > 0) {
							var htmls = "",countMsg = false;
							for(var i = 0; i < s2; i++) {
								var checked = "";
								var ifm_id2 = data.returnData[i].ifm_id;
								var num = ifmIdArr.length;
								if(isSensitiveFlag == 0){
									for(var nn = 0; nn < num; nn++) {
										if(getSs(ifm_id2)||getSs(ifm_id2)==0) {
											checked = "checked";
											break;
										} else {
											checked = "";
										}
									}
									if(data.returnData[i].ifm_note==null){
										data.returnData[i].ifm_note = "";
									}
									htmls += '<tr class="td infoLlist"><td class="tc w60"><span class="ui_checkbox '  + checked + '" ifm_id=' + data.returnData[i].ifm_id + ' ifm_name=' + data.returnData[i].ifm_name + '></span></td><td class="tc w150 tName"><font>' + data.returnData[i].ifm_name + '</font></td><td class="tc w536"><font title="'+ data.returnData[i].ifm_note +'">' + data.returnData[i].ifm_note + '</font></td>';
								}else if(isSensitiveFlag == 1){
									for(var nn = 0; nn < num; nn++) {
										if(getSs(ifm_id2)||getSs(ifm_id2)==0) {
											checked = "checked";
											break;
										} else {
											checked = "";
										}
									}
									if(checked == "checked"){
										for(var nn = 0; nn < num; nn++) {
											if(getSs2(ifm_id2)||getSs2(ifm_id2)==0) {
												checked = "checked";
												break;
											} else {
												checked = "";
											}
										}
										if(data.returnData[i].ifm_note==null){
											data.returnData[i].ifm_note = "";
										}
										htmls += '<tr class="td infoLlist"><td class="tc w60"><span class="ui_radio '  + checked + '" ifm_id= ' + data.returnData[i].ifm_id + '></span></td><td class="tc w150 tName"><font class="ifmSensitiveNamesS">' + data.returnData[i].ifm_name + '</font></td><td class="tc w536"><font class="ifmSensitiveNotesS" title="'+ data.returnData[i].ifm_note +'">' + data.returnData[i].ifm_note + '</font></td>';
										countMsg = true;
									}
								}
							}
							$(".headDiv").html(strHead);
							if(!countMsg && isSensitiveFlag==1){
								$("#CustomsAreaList2").html("<tr><td class='tc h40' colspan='3'>暂无敏感信息方案！</td></tr>");
							}
							if(htmls){
								_obj.html(htmls);
							}
							if(isSensitiveFlag==0){
								$(".pageDiv").html(strPage);
								//加入分页
								paging.loadPage(data);
								//判断是否全选
								checkTrueFalse();
							}
						}
						if(s2 < 1) {
							$(".headDiv").html(strHead);
							_obj.html("<tr><td class='tc h40' colspan='3'>很遗憾，没有查询到相关的数据！</td></tr>");
						}
					} else if(data.returnCode == 999994) {
						setUserTimeout(data);
					} else {
						layer.msg(data.returnMessage, 2, -1);
					}
				},
				error: function(message) {
					layer.msg("操作失败，请重试！", 2, -1);
				},
				beforeSend: function() {
					var imgGif = "<p class='loadingGif'></p>";
					_obj.html(imgGif);
				}
			});
		}
	}
	//复选框
	$(".infoLlist .ui_checkbox").live("click", function() {
		if($(this).hasClass("checked")) {
			$(this).removeClass("checked");
			if($(this).attr("ifm_id")!=undefined){
				var qc=getSs($(this).attr("ifm_id"));
				if(qc||qc==0){
					var ifmIdsArr=window.ifmIds.split(','),
						ifmNamesArr=window.ifmNames.split(',');
					ifmIdsArr.splice(qc,1);
					ifmNamesArr.splice(qc,1);
					window.ifmIds=ifmIdsArr.join(',');
					window.ifmNames=ifmNamesArr.join(',');
				}
			}
		} else {
			$(this).addClass("checked");
			if($(this).attr("ifm_id")!=undefined){
				var qc=getSs($(this).attr("ifm_id"));
				if(!qc){
					if(window.ifmIds!=""){
						window.ifmIds+=(','+$(this).attr("ifm_id"));
						window.ifmNames+=(','+$(this).attr("ifm_name"));
					}else{
						window.ifmIds+=$(this).attr("ifm_id");
						window.ifmNames+=$(this).attr("ifm_name");
					}
				}
			}
		}
	});
	
	//单选框
	$(".infoLlist .ui_radio").live("click", function() {
		if($(this).hasClass("checked")){
			$(this).removeClass("checked");
			window.ifmId = null;
		}else{
			$("span").removeClass("checked");
			$(this).addClass("checked");
			window.ifmId = $(this).attr("ifm_id");
		}
	});
	$(".editExaDataBtn").live("click", function() {
		var strId = $(this).attr('ifm_id');
		var ifmIdArr = strId.split(",");
		edit.qTagList($(this), ifmIdArr, {group_id:groupId}, curPage, numList);
	});
	
	$(".editSensitiveBtn").live("click", function() {
		var ifmIdArr = window.ifmIds.split(",");
		edit.qTagList($(this), ifmIdArr, {group_id:groupId}, 1, 10000000);
	});

	$("#sensitiveQueryBtn").live("click",function(){
		publicQDataList3($("#sensitiveIfmName"),$("#sensitiveIfmNote"),".ifmSensitiveNamesS",".ifmSensitiveNotesS");
	});
	$('.enterKeyDownElement2, .enterKeyDownElement3').keydown(function(e){
		if(e.keyCode==13){
			publicQDataList3($("#sensitiveIfmName"),$("#sensitiveIfmNote"),".ifmSensitiveNamesS",".ifmSensitiveNotesS");
		}
	});

	function publicQDataList3(_thisName,_thisNote,nameTextObj,noteTextObj){	
		var kVName = $.trim(_thisName.val());
		var kVNote = $.trim(_thisNote.val());
		$("#CustomsAreaList2 .infoLlist").each(function(){
			var name = $(this).children().children(nameTextObj).text();
			var note = $(this).children().children(noteTextObj).text();
			var isNameOf = $.trim(name.indexOf(kVName));
			var isNoteOf = $.trim(note.indexOf(kVNote));
			if(kVName!=""&&kVNote==""){
				if(isNameOf>-1){
					$(this).show();
				}else{
					$(this).hide();
				}
			}else if(kVName==""&&kVNote!=""){
				if(isNoteOf>-1){
					$(this).show();
				}else{
					$(this).hide();
				}
			}else if(kVName!=""&&kVNote!=""){
				if(isNameOf>-1&&isNoteOf>-1){
					$(this).show();
				}else{
					$(this).hide();
				}
			}else{
				$(this).show();
			}
		});
	}
	
	$(".selectAllAreaGoGo .allSel").live("click", function() {
		var len = $("#CustomsAreaList .infoLlist .ui_checkbox").length;
		//判断在点击全选按钮之前，列表中是否存在已勾选的状态
		for(var ii=0;ii<len;ii++){
			if($("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).hasClass("checked")){
				$("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).attr("data-select","true");
			}else{
				$("#CustomsAreaList .infoLlist .ui_checkbox").eq(ii).removeAttr("data-select");
			}
		}
		if(!$(this).hasClass("checked")) {
			$("#CustomsAreaList .infoLlist .ui_checkbox, .allSel").addClass("checked");
			for(var i=0;i<len;i++){
				if($("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("data-select")=="true"){
					var	nn="", name="";
				}else{
					var nn= $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("ifm_id"),
						name= $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr("ifm_name");
				}
				var qc=getSs(nn);
				if(!qc){
					if(window.ifmIds!=""){
						window.ifmIds+=(nn!="" ? (',' + nn) : nn);
						window.ifmNames+=(name!="" ? (',' + name) : name);
					}else{
						window.ifmIds+=nn;
						window.ifmNames+=name;
					}
				}
			}

		} else {
			$("#CustomsAreaList .infoLlist .ui_checkbox, .allSel").removeClass("checked");
			for(var i=0;i<len;i++){
				var nn = "";
				nn = $("#CustomsAreaList .infoLlist .ui_checkbox").eq(i).attr('ifm_id');
				var qc=getSs(nn);
				if(qc||qc==0){
					var ifmIdsArr=window.ifmIds.split(','),
					 	ifmNamesArr=window.ifmNames.split(',');
					ifmIdsArr.splice(qc,1);
					ifmNamesArr.splice(qc,1);
					window.ifmIds=ifmIdsArr.join(',');
					window.ifmNames=ifmNamesArr.join(',');
				}
			}
		} 
	});

	$("#CustomsAreaList .infoLlist .ui_checkbox").live("click", function() {
		checkTrueFalse();
	});

	function checkTrueFalse() {
		var isTrue = "true";
		$("#CustomsAreaList .infoLlist .ui_checkbox").each(function() {
			if(!$(this).hasClass("checked")) {
				isTrue = "false";
				return;
			}
		});
		if(isTrue == "false") {
			$(".selectAllAreaGoGo .allSel").removeClass("checked");
		} else {
			$(".selectAllAreaGoGo .allSel").addClass("checked");
		}
	}
	
	//点击查询
	$("#checkQueryBtn").live("click", function() {
		curPage = 1;
		qDataFun(curPage);
	});
	
	$('.enterKeyDownElement').keydown(function(e) {
		if(e.keyCode == 13) {
			curPage = 1;
			qDataFun(1);
		}
	});
	//点击触发换页的按钮
	$("#pageArea .pNumBtn a, #pageAreaSensitive .pNumBtn a").live("click", function() {
		curPage = parseInt($(this).attr("toPage"));
		qDataFun(curPage);
	});

	//点击触发分批显示的按钮
	$("#pageArea .columnsPage a, #pageAreaSensitive .columnsPage a").live("click", function() {
		numList = parseInt($(this).text());
		curPage = 1;
		qDataFun(curPage);
		subPage = $(this).index();
	});
	//跳转
	$("#pageArea .gopg .btn, #pageAreaSensitive .gopg .btn").live("click", function() {
		if(isSensitiveFlag==0){
			curPage = parseInt($("#pageArea .gopg .txt").val());
		}else if(isSensitiveFlag==1){
			curPage = parseInt($("#pageAreaSensitive .gopg .txt").val());
		}
		
		//判断输入的页数是否大于最大的页数
		if(curPage>countPage){
			curPage=countPage;
		}
		if(curPage>0){
			qDataFun(curPage);
		}
	});

	function qDataFun(curPages) {
		selectJsonData = null;
		ifmName = $("#ifmName").val();
		ifmNote = $("#ifmNote").val();
		selectJsonData = {
			group_id: groupId,
			ifm_name: ifmName,
			ifm_note: ifmNote
		};
		var rscArr2 =  $(".editExaDataBtn").attr("ifm_id").split(",");
		edit.qTagList( $(".editExaDataBtn"), rscArr2, selectJsonData, curPages, numList);
	};

	/*
	 * 分页
	 * */
	var numList =10 ;	//每页列数
	var curPage = 1;  //默认第一页
	var subPage=0;  //批量显示添加默认落点
	var totalPage=9; //最多显示分页数
	var selectJsonData = "";
	var countPage = 0;//页数总计
	function jsCk(t){
		if(!/^[1-9][0-9]*$/g.test(t.value)){
			t.value="";
			return false;
		}
	}
	var paging = {
		//加载分页
		"loadPage":function(data){
			var pCount = data.totalPages;//页数
			countPage = pCount;
			var pNums =  data.totalRecords;//总计条数
			var s1 = (totalPage-1)/2;
			var start_page = curPage - s1;
			var end_page = curPage + s1;
			if(start_page<=0){
				end_page = end_page - start_page + 1;
				start_page = 1;
			}
			if(end_page>pCount){
				end_page = pCount;
			}	  		
			var prevHtml ='<a toPage="'+(curPage-1)+'" href="javascript:void(0);"   class="str">&lt;</a>';
			var nextHtml ='<a toPage="'+(curPage+1)+'" href="javascript:void(0);"  class="end" >&gt;</a>';
			if(curPage<2)prevHtml="";
			if(curPage>=pCount)nextHtml="";
			var ppHtml = "";
			for(i=start_page;i<=end_page;i++){
			   var cur = "";
			   if(curPage==i)cur='class="cur"';
			   ppHtml = ppHtml+'<a toPage="'+i+'" href="javascript:void(0);"  '+cur+'>'+i+'</a>';
			}
			var pageHtml = '<span class="ic fl pr20 pCount">共<b>'+pNums+'</b>条记录</span><span class="sw fl pr20 columnsPage">显示 <a href="javascipr:void(0);" class="cur">10</a><a href="javascipr:void(0);" class="cur">50</a><a href="javascipr:void(0);" class="cur">全部</a></span><span class="gopg fr"><span class="fl">跳转到</span><input type="button" class="btn" value="go"><input type="text" min="1" class="txt" onkeyup="jsCk(this)"></span><div class="pg fr pNumBtn">'+prevHtml+ppHtml+nextHtml+'</div>';
			if(isSensitiveFlag==0){
				var pageArea = $('#pageArea');
				pageArea.html(pageHtml);
			}
//			else if(isSensitiveFlag==1){
//				var pageAreaSensitive = $('#pageAreaSensitive');
//				pageAreaSensitive.html(pageHtml);
//			}

  			//每页显示指定的数量
  			var dd = pNums/10;
  			var ddHtmls = "";
  			var pCur = 0;
  			if(pNums>0){
  				pCur=0;
  				if(isSensitiveFlag==0){
  					pageArea.show();
  				}else if(isSensitiveFlag==1){
  					pageAreaSensitive.show();
  				}
  				
  			}else if(pNums==0){
  				pCur=4;
  				if(isSensitiveFlag==0){
  					pageArea.hide();
  				}else if(isSensitiveFlag==1){
  					pageAreaSensitive.hide();
  				}
  			}
			if(isSensitiveFlag==0){
				$("#pageArea .columnsPage").html("显示 <a href='javascript:void(0);'>10</a><a href='javascript:void(0);'>20</a><a href='javascript:void(0);'>50</a><a href='javascript:void(0);'>100</a>");
	  			$("#pageArea .columnsPage a").removeClass("cur").eq(subPage).addClass("cur");
	  			var s = 4; 
	  			for(var i=0;i<pCur;i++){
	  				$("#pageArea .columnsPage a").eq(s).remove();
	  				s -=1;
	  			}
			}
//			else if(isSensitiveFlag==1){
//	  			$("#pageAreaSensitive .columnsPage").html("显示 <a href='javascript:void(0);'>10</a><a href='javascript:void(0);'>20</a><a href='javascript:void(0);'>50</a><a href='javascript:void(0);'>全部</a>");
//	  			$("#pageAreaSensitive .columnsPage a").removeClass("cur").eq(subPage).addClass("cur");
//	  			var s = 4; 
//	  			for(var i=0;i<pCur;i++){
//	  				$("#pageAreaSensitive .columnsPage a").eq(s).remove();
//	  				s -=1;
//	  			}
//			}
		}
	}
});
